package class01;

/**
 * @author Gong Cheng
 * @date 2021/2/25 10:05 上午
 **/
public class Code02_BubbleSort {

    public static void bubbleSort(int[] arr){
        if (arr == null || arr.length < 2){
            return ;
        }
        for (int e = arr.length - 1; e > 0;e--){
            for(int i = 0;i < e; i++){
                if(arr[i] > arr[i+1]){
                    swap(arr,i,i+1);
                }
            }
        }
    }

    public static void swap(int[] arr, int i, int j) {
        arr[i] = arr[i] ^ arr[j];
        arr[j] = arr[i] ^ arr[j];
        arr[i] = arr[i] ^ arr[j];

    }
}
